package com.work.demo_01.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.work.demo_01.Exception.ServiceException;
import com.work.demo_01.entity.User;
import com.work.demo_01.mapper.UserMapper;
import com.work.demo_01.service.UserService;
import com.work.demo_01.utils.VerCodeGenerateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

//    用户注册
    @Override
    public void register(User user) {
        userMapper.insert(user);
    }

//    根据用户名查询用户信息
    @Override
    public User findByUsername(String username) {
        User result = userMapper.findByUsername(username);
        return result;
    }

//    查询出所有用户数据
    @Override
    public List<User> findAllUser() {
        List<User> result = userMapper.findAllUser();
        return result;
    }

    @Override
    public PageInfo splitPage(int pageNum, int pageSize) {
//        做分页查询，启动分页功能插件
        PageHelper.startPage(pageNum,pageSize);
//        调用持久层查询方法，将查出来的数据放入分页插件中，自动进行分页以及相关的计算
        List<User> list = userMapper.findAllUser();
//        将集合放入分页对象，自动进行数据拆分
        PageInfo<User> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<User> getUser(User user) {
        List<User> result = userMapper.getUser(user);
        return result;
    }

}
